package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.AppointmentDTO;
import com.hs.sfzy.entity.Article;
import com.hs.sfzy.entity.Consult;
import com.hs.sfzy.service.ConsultService;
import com.hs.sfzy.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultController
 * @Description TODO
 * @Author 李明辉
 * @Date 2024年10月24日 11:14
 * @Version 1.0
 */
@RestController
@RequestMapping("/consult")
public class ConsultController {
    @Autowired
    private ConsultService consultService;
    @GetMapping("/findAll")
    public Result selectAll(Consult consult) {
        List<Consult> list = consultService.findAll(consult);
        return  Result.success(list);
    }

    @PostMapping("/add")
    public Result insert(@RequestBody Consult consult) {
        int num = consultService.insert(consult);
        if (num != 0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }
    @GetMapping("/findByPage")
    public Result selectByPage(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "10") int pageSize,
            Consult consult){

        PageInfo<Consult> info = consultService.selectByPageInfo(pageNum, pageSize, consult);
        return Result.success(info);
    }

    @PutMapping("/edit")
    public Result update(@RequestBody Consult  consult) {
        int num = consultService.update(consult);
        if (num != 0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id) {
        int num = consultService.delete(id);
        if (num == 1){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }

    /**
     * 根据id查询咨询师
     * @author QinKunPeng
     * @date 2024/10/24 19:57
     * @param id
     * @return java.lang.Object
     */
    @GetMapping("/{id}")
    public Object getConsultById(@PathVariable("id") Long id) {
        Consult consult = consultService.selectSimpleById(id);
        return Result.success(consult);
    }


    @GetMapping("/getIdAndName")
    @ApiOperation("获取咨询师id与name")
    public Result<List<Consult>> getIdAndName() {
        return Result.success(consultService.getIdAndName());
    }


    @GetMapping("/findByInfo")
    public Result findByInfo(AppointmentDTO appointmentDTO){
        List<Consult> infoList = consultService.findByInfo(appointmentDTO);
        return Result.success(infoList);
    }

}
